package com.cy.pj.sys.web.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.time.LocalTime;
/*springWeb模块定义的拦截器，其接口规范为HandlerInterceptor
* 当前*/

public class TimeAccessInterceptor implements HandlerInterceptor {
    /*后端handler方法执行之前
    * request请求对象
    * response响应对象
    * handler目标处理器对象
    * */


    @Override
    public boolean preHandle(HttpServletRequest request,
                             HttpServletResponse response,
                             Object handler) throws Exception {
        //testRequestInfo(request,handler);
        LocalTime now=LocalTime.now();//JDK8 中的时间对象
        int hour=now.getHour();//获取当前时间对应小时
        //System.out.println("hour="+hour);
        //log.info("hour {}",hour);
        if(hour<=9||hour>=18)
            throw new RuntimeException("请在指定时间访问");
        return true;
    }
}
